package com.woniuxy.service.impl;

import com.woniuxy.dao.PaperDao;
import com.woniuxy.dao.StudentExamDao;
import com.woniuxy.entity.ExamResult;
import com.woniuxy.entity.PaperObject;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.StudentExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author:deng
 * @time:2022/5/5 18:56
 * @描述：学生考试service
 */
@Service
public class StudentExamServiceImpl implements StudentExamService {

    @Autowired
    StudentExamDao studentExamDao;
    @Override
    public Map<Integer, List<?>> findTopticByPid(Integer paperId) {
        /*查询选择题*/
        List<PaperObject> singleSelectTopic = studentExamDao.findSingleSelectTopic(paperId);
        /*查询多选题*/
        List<PaperObject> doubleSelectTopic = studentExamDao.findDoubleSelectTopic(paperId);
        /*查询判断题*/
        List<PaperObject> judgeTopic = studentExamDao.findJudgeTopic(paperId);
        /*查询填空题*/
        List<PaperObject> fillTopic = studentExamDao.findFillTopic(paperId);
        /*查询简答题*/
        List<PaperObject> answerTopic = studentExamDao.findAnswerTopic(paperId);
        Map<Integer, List<?>> map = new HashMap<>();
        map.put(1,singleSelectTopic);
        map.put(2,doubleSelectTopic);
        map.put(3,judgeTopic);
        map.put(4,fillTopic);
        map.put(5,answerTopic);
        return map;
    }

    /*封装学生的答案*/
    @Override
    public ResponseEntity setAnswerScore(ExamResult examResult) {
        int i=studentExamDao.setAnswerScore(examResult);
        //修改已考代码
        int statusi=studentExamDao.setExamStatus(examResult.getEinformationId(),examResult.getExamPublishExamId());
        if (i > 0) {
            return ResponseEntity.SUCCESSFUL;
        }
        else {
            return ResponseEntity.FAIL;
        }
    }
}
